package com.zx.platform.utils;

import com.zx.map.utils.SUConstants;
import org.apache.commons.lang3.StringUtils;

import java.text.DecimalFormat;
import java.util.Collection;
import java.util.List;
import java.util.Map;


/**
 * 字符串工具类
 * add by wenjw 2015.5.13
 */
public class StrUtils extends StringUtils{


	/**
	 * 连接字符串
	 * @param
	 * @return
	 */
	public static String contract(String value1,String value2,String split) {
		if(StrUtils.isEmpty(value1)){
			value1 = value2+split;
		}else{
			value1 = value1+value2+split;
		}
		return value1;
	}
	//保留2位小数
	public static double get2Double(double a){
	    DecimalFormat df=new DecimalFormat("0.00");
	    return Double.parseDouble(df.format(a));
	}

	/**
	 * 判断对象是否Empty(null或元素为0)<br>
	 * 实用于对如下对象做判断:String Collection及其子类 Map及其子类
	 *
	 * @param pObj
	 *            待检查对象
	 * @return boolean 返回的布尔值
	 */
	@SuppressWarnings("rawtypes")
	public static boolean isEmpty(Object pObj) {
		if (pObj == null)
			return true;

		if (pObj instanceof String) {
			if (((String) pObj).length() == 0) {
				return true;
			}
		} else if (pObj instanceof Collection) {
			if (((Collection) pObj).size() == 0) {
				return true;
			}
		} else if (pObj instanceof Map) {
			if (((Map) pObj).size() == 0) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 判断对象是否为NotEmpty(!null或元素>0)<br>
	 * 实用于对如下对象做判断:String Collection及其子类 Map及其子类
	 *
	 * @param pObj
	 *            待检查对象
	 * @return boolean 返回的布尔值
	 */
	@SuppressWarnings("rawtypes")
	public static boolean isNotEmpty(Object pObj) {
		if (pObj == null)
			return false;

		if (pObj instanceof String) {
			if (((String) pObj).length() == 0) {
				return false;
			}
		} else if (pObj instanceof Collection) {
			if (((Collection) pObj).size() == 0) {
				return false;
			}
		} else if (pObj instanceof Map) {
			if (((Map) pObj).size() == 0) {
				return false;
			}
		}
		return true;
	}

	public static boolean isEmpty(String str,boolean trim) {
		String temp = str;
		if(trim){
			return str == null || "".equals(temp.trim());
		}else{
			return str == null || "".equals(temp);
		}


	}

	/**
	 * null  全空格
	 * @param str
	 * @return
	 */
	public static boolean isBlank(String str) {
		if(str == null ||str.trim().isEmpty()) {
			return true;
		} else {
			return false;
		}
	}

	public static boolean isNotBlank(String str) {
		return !isBlank(str);
	}

	/**
	 * 返回交易类型
	 * @param transType
	 * @return
	 */
	public static String getTransTypeById(String transType) {
		if (SUConstants.TRANSTYPE_INCOME.equals(transType)) {
			return "扫码收款";
		} else if (SUConstants.TRANSTYPE_NOCARDINCOME.equals(transType)) {
			return "无卡收款";
		} else if (SUConstants.TRANSTYPE_CARDINCOME.equals(transType)) {
			return "刷卡收款";
		} else if (SUConstants.TRANSTYPE_OFFLINE_INCOME.equals(transType)) {
			return "线下扫码";
		} else if (SUConstants.TRANSTYPE_AGENT_PROMATION.equals(transType)) {
			return "代理高迁";
		} else if (SUConstants.TRANSTYPE_RECHARGE.equals(transType)) {
			return "线上充值";
		} else if (SUConstants.TRANSTYPE_T0ENCASH.equals(transType)) {
			return "即时取现";
		} else if (SUConstants.TRANSTYPE_T1ENCASH.equals(transType)) {
			return "T+1取现";
		} else {
			return "";
		}
	}

	/**
	 * 交易记录  remark对应的提示
	 * @param remark
	 * @return
	 */
	public static String getCustAcctLogRemarkById(String remark) {
		if(isBlank(remark)){
			return "";
		} else if ("1".equals(remark)) {
			return "支付宝";
		} else if ("2".equals(remark)){
			return "微信";
		} else {
			return "";
		}
	}


}
